<?php

use Phinx\Seed\AbstractSeed;
use Faker\Factory as FakerFactory;

class ChapterReadSeeder extends AbstractSeed
{
    public function getDependencies(): array
    {
        return [
            'ChapterSeeder',
        ];
    }

    /**
     * Run Method.
     *
     * Write your database seeder using this method.
     *
     * More information on writing seeders is available here:
     * https://book.cakephp.org/phinx/0/en/seeding.html
     */
    public function run()
    {
        $faker = FakerFactory::create('zh_CN');

        $chapters = $this->fetchAll("SELECT * FROM kg_chapter");

        $rows = [];
        foreach ($chapters as $chapter){
            $rows[] = [
                'course_id' => $chapter['course_id'],
                'chapter_id' => $chapter['id'],
                'content'=>$faker->text(50),
                'create_time' => $faker->unixTime,
                'update_time' => $faker->unixTime,
            ];
        }

        $this->table('kg_chapter_read')->insert($rows)->saveData();
    }

}
